/**
 * @file tilesettester.cpp
 * @brief TileSet automated tests implementation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3 of the License.
 *
 * @author VestniK (Sergey N.Vidyuk)
 * @date 23 Oct 2008
 */
#include "tilesettester.h"

#include <QtCore>

#include "defaults.h"
#include "tileset.h"
#include "tile.h"

using namespace mjn;

void TileSetTester::fillingTest() {
   TileSet set;
   set.fillSet();
   QCOMPARE( set.getTilesCount() , TILE_COUNT );
   /// @todo Check that TileSet filled with correct set of tiles according to mahjong rules
}

void TileSetTester::clearTest() {
   TileSet set;
   set.fillSet();
   set.clearSet();
   QCOMPARE( set.getTilesCount() , 0 );
}

void TileSetTester::getTilesCountTest() {
   TileSet set;
   set.fillSet();
   int ActualSize = set.getTilesList().size();
   QCOMPARE(set.getTilesCount() , ActualSize);
}

void TileSetTester::tileValidationTest() {
   TileSet set;
   set.fillSet();
   QList<Tile::TileSuits> all_suits;
   all_suits << Tile::Dot << Tile::Bamboo << Tile::Character << Tile::Wind;
   all_suits << Tile::Dragon << Tile::Season << Tile::Flower << Tile::NullSuit;

   QList<Tile::TileRanks> all_ranks;
   all_ranks << Tile::One << Tile::Two << Tile::Three << Tile::Four <<Tile::Five;
   all_ranks << Tile::Six << Tile::Seven << Tile::Eight << Tile::Nine;
   all_ranks << Tile::Red << Tile::Green << Tile::White;
   all_ranks << Tile::East << Tile::South << Tile::West << Tile::North;
   all_ranks << Tile::Spring << Tile::Summer << Tile::Autumn << Tile::Winter;
   all_ranks << Tile::Orchid << Tile::Chrisantemium << Tile::BambooFlower << Tile::Plum;
   all_ranks << Tile::NullRank;

   foreach ( Tile::TileSuits suit, all_suits ) {
      foreach ( Tile::TileRanks rank, all_ranks ) {
         Tile test(suit, rank);
         bool inSet = false;
         foreach ( Tile t, set.getTilesList() ) {
            if ( test == t ) {
               inSet = true;
               break;
            }
         }
         QCOMPARE(test.isValid() , inSet);
      }
   }
}
